const vm = new Vue({
    el: '#main',
    data: {
        show: {
            unused: true,
        },
        data: {
            unusedLength: 0,
            unused: [],
            usedLength: 0,
            used: [],
        },
    },
    methods: {
        toggleUnused(b) {
            this.show.unused = b;
        },
        handleDate,
    },
});

function apiready() {
    fxj.fixLayout();
    fixLayout();
    reqCouponList();
}

function fixLayout() {
    const labelGroup = document.querySelector('.label-btn-group');
    labelGroup.style.maxHeight = labelGroup.clientHeight + 'px';
    const headerH = document.querySelector('header').clientHeight;
    document.getElementById('main').style.maxHeight = screen.height - headerH + 'px';
    const content = document.getElementById('content');
    content.style.maxHeight = screen.height - labelGroup.clientHeight - headerH + 'px';
}

async function reqCouponList() {
    const res = await ajax({
        url: 'home/userCenter/getUserCouponList',
        data: {
            pageNum: 1,
        },
    });
    if (res.err !== 0) {
        mui.toast(res.msg);
        return;
    }
    vm.data.used = res.data.outated;
    vm.data.usedLength = res.data.outated.length;
    vm.data.unused = res.data.useable;
    vm.data.unusedLength = res.data.useable.length;
}

function handleDate(dateStr) {
    return new Date(Number(dateStr + '000')).toLocaleDateString().replace(/\//g, '.');
}